package com.hy.service.impl;

import com.hy.bean.*;
import com.hy.dao.EmployeetableDao;
import com.hy.dao.impl.EmployeetableDaoImpl;
import com.hy.service.EmployeetableService;
import com.hy.vo.EmpDeptVo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeetableServiceImpl implements EmployeetableService {
    private final EmployeetableDao employeetableDao = new EmployeetableDaoImpl();

    @Override
    public PageResult<EmpDeptVo> list(Integer currPage, Integer pageSize, Employeetable employeetable){
        List<EmpDeptVo> listEmpDempVo = employeetableDao.queryAllByLimit(currPage, pageSize, employeetable);
        Long count = employeetableDao.count(employeetable);
        PageResult<EmpDeptVo> page = new PageResult<>(listEmpDempVo,count,currPage,pageSize);
        return page;
    }

    @Override
    public RespBean getEmpDeptVo(String employeeNumber){
        return RespBean.success(null,employeetableDao.queryByEmployeeNumber(employeeNumber));
    }

    @Override
    public RespBean save (Employeetable employeetable){
        if (employeetableDao.insert(employeetable) > 0){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }


    @Override
    public RespBean deletById(Integer id) {
        if (employeetableDao.deleteById(id) > 0) {
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @Override
    public RespBean updateByid(Employeetable employeetable){
        if (employeetableDao.update(employeetable) > 0){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }
}